package org.dromara.solonplugins.kafka1;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.noear.solon.annotation.Init;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;

/**
 * Solon-kafka1 插件入口 参考文档{@link https://kafka.apache.org/090/documentation.html}
 * 
 * @author: xls-web (小xu中年)
 */
public class XPluginImpl implements Plugin{
	
	private Kafka1ProducerTemplate kpt;
	
	@Override
    public void start(AppContext context) {
		Kafka1Manager km = new Kafka1Manager();
		KafkaProducer<String, String> producer = km.getProducer(context.cfg());
		if(producer!=null) {
			kpt = new Kafka1ProducerTemplate(producer);
//			context.beanInject(kpt);//这里注入Kafka1ProducerTemplate
			context.wrapAndPut(Kafka1ProducerTemplate.class, kpt);
		}
	}

    @Override
    public void stop() throws Throwable {
       if(kpt!=null) {
    	   kpt.stop();
       }
    }

}
